package com.yuxi.al.leercode;

/**
 * 将一个数拆开相加
 * Created by yuxi on 2017/4/7.
 */
public class AddDigits {
    public static void main(String[] args) {
        int num = 35;
        int res = addDigits(num);
        System.out.println(res);
    }

    /**
     * 是个数学题 大神的推理
     * <p>
     * dr(n) = 0 if n == 0
     * dr(n) = (b-1) if n != 0 and n % (b-1) == 0
     * dr(n) = n mod (b-1) if n % (b-1) != 0
     * or
     * dr(n) = 1 + (n - 1) % 9
     *
     * @param num
     * @return
     */
    private static int addDigits(int num) {
        return 1 + (num - 1) % 9;
    }
}
